cmake_minimum_required(VERSION 3.18 FATAL_ERROR)
project(dct_operator LANGUAGES CXX CUDA)

set ( PRJ_SRC_LIST )
set ( PRJ_HEADER_LIST )
set ( PRJ_LIBRARIES )
set ( PRJ_INCLUDE_DIRS )
set ( PRJ_COMPILE_OPTIONS )

set ( CUDA_ENABLE true )
if ( CUDA_ENABLE )
    enable_language( CUDA )
    #list ( APPEND PRJ_COMPILE_OPTIONS -Xcompiler )
endif()

file ( GLOB root_header_files "${CMAKE_CURRENT_SOURCE_DIR}/*.h" )
file ( GLOB root_src_files "${CMAKE_CURRENT_SOURCE_DIR}/*.cpp" )
file ( GLOB root_cuda_files "${CMAKE_CURRENT_SOURCE_DIR}/*.cu" )
file ( GLOB root_cuda_header_files "${CMAKE_CURRENT_SOURCE_DIR}/*.cuh" )

list ( APPEND PRJ_HEADER_LIST ${root_header_files} ${root_cuda_header_files} )
list ( APPEND PRJ_SRC_LIST ${root_src_files} )
list ( APPEND PRJ_SRC_LIST ${root_cuda_files} )

add_executable ( ${PROJECT_NAME} ${PRJ_SRC_LIST} ${PRJ_HEADER_LIST} )

target_include_directories ( ${PROJECT_NAME}
    PRIVATE
        ${PRJ_INCLUDE_DIRS}
)

if(CMAKE_BUILD_TYPE STREQUAL "Debug")
    target_compile_options(${PROJECT_NAME} PRIVATE $<$<COMPILE_LANGUAGE:CUDA>:-G>)
endif()

target_compile_features ( ${PROJECT_NAME} 
    PUBLIC 
        cuda_std_14
        cxx_std_14
)

set_target_properties (    ${PROJECT_NAME}
    PROPERTIES
        CUDA_ARCHITECTURES "50;52;72;75"
        CUDA_SEPARABLE_COMPILATION ON
)

target_compile_options ( ${PROJECT_NAME}
    PRIVATE
        ${PRJ_COMPILE_OPTIONS}
)

target_link_libraries ( ${PROJECT_NAME} 
    PRIVATE 
        ${PRJ_LIBRARIES} cufft cudart
)

add_definitions(-DALWAYS_USE_MALLOC_MANAGED)

